package com.ty.controller;

import cn.hutool.core.bean.BeanUtil;
import com.ty.bean.CustomerInquiry;
import com.ty.common.bean.PageBean;
import com.ty.common.bean.ResultBean;
import com.ty.common.controller.BaseController;
import com.ty.query.CustomerInquiryQuery;
import com.ty.service.CustomerInquiryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Api(tags = "客户询价单")
@RequestMapping("/api")
public class CustomerInquiryController extends BaseController {

    @Autowired
    CustomerInquiryService customerInquiryService;

    @ApiOperation("保存询价单")
    @PostMapping("/customerInquiry")
    public ResultBean save(@RequestBody CustomerInquiry customerInquiry) {
        int rs = customerInquiryService.save(customerInquiry);
        return saveResult(rs);
    }

    @ApiOperation("询价单列表")
    @PostMapping("/customerInquiry/list")
    public ResultBean<PageBean> query(@RequestBody CustomerInquiryQuery query) {
        PageBean pageBean = customerInquiryService.queryByMap(BeanUtil.beanToMap(query));
        return success("询价单列表", pageBean);
    }


    @ApiOperation("询价详情")
    @GetMapping("/customerInquiry")
    public ResultBean get(@RequestParam(required = true) int id) {
        CustomerInquiry inquiry = customerInquiryService.get(id);
        return success("询价详情", inquiry);
    }

    @ApiOperation("根据客户id查询最近询价单id")
    @GetMapping("/customerInquiry/latest")
    public ResultBean queryLatestInquriy(@RequestParam(required = true) int cid) {
        return success("询价单id", customerInquiryService.queryLatestInquiry(cid));
    }


    @ApiOperation("根据询价单id查询明细")
    @GetMapping("/customerInquiry/detail")
    public ResultBean queryInquiryDetail(@RequestParam(required = true) int id) {
        return success("产品",customerInquiryService.queryInquiryDetail(id));
    }
}